/**
 * Created by Freeman on 2016/7/14.
 */

import {USER_SELECT,SEND_TEXT,WRITE_TEXT} from '../types'
let now = new Date();
const state = {
    items: [
        {
            userId: 2,
            messages: [
                {
                    text: 'Hello，这是一个基于Vue + Webpack构建的简单chat示例，聊天记录保存在localStorge。简单演示了Vue的基础特性和webpack配置。',
                    date: now
                },
                {
                    text: '项目地址: https://github.com/coffcer/vue-chat',
                    date: now
                }
            ]
        },
        {
            userId: 3,
            messages: []
        }
    ],
    sessionIndex:0,
    text:''
}

const mutations = {
    [USER_SELECT](state,action){
        state.sessionIndex = action
    },
    [WRITE_TEXT](state,text){
        state.text = text
    },
    [SEND_TEXT](state){
        state.items[state.sessionIndex].messages.push({
            text: state.text,
            date: new Date(),
            self: true
        });
        state.text = ''
    }
}

export default  {
    state,
    mutations
}